from typing import List


class Solution:
    def rob(self, nums: List[int]) -> int:
        if len(nums) < 2:
            return max(nums)
        nums_1 = nums[1:]
        nums_2 = nums[:len(nums) - 1]
        return max(self.rob_one(nums_1), self.rob_one(nums_2))

    def rob_one(self, nums_i: List[int]) -> int:
        if len(nums_i) < 2:
            return max(nums_i)
        dp = [0] * len(nums_i)
        dp[0] = nums_i[0]
        dp[1] = max(nums_i[0:2])
        for i in range(2, len(nums_i)):
            dp[i] = max(nums_i[i] + dp[i - 2], dp[i - 1])
        return dp[-1]


